SSSAPP
    .directive('pwdlogin', ['$rootScope', '$rjax', '$interval', '$timeout', function ($rootScope, $rjax, $interval, $timeout) {
        // Runs during compile
        return {
            scope: true, // {} = isolate, true = child, false/undefined = no change
            templateUrl: '/home/index/pwd_login',
            replace: false,
            link: function ($scope) {
                //先检查登录状态
                $scope.state = 'login';
                $scope.hint = '新用户？注册';
                $scope.operate = '登录';
                $scope.GetDisabled = false;
                $scope.Hint = '获取验证码';
                $scope.telhint = '手机号';
                $scope.pwdhint = '登录密码';
                $scope.changeState = function () {
                    if ($scope.hint == '老用户？') {
                        $scope.hint = '新用户？注册';
                        $scope.operate = '登录';
                        $scope.telhint = '手机号';
                        $scope.pwdhint = '登录密码';
                        $scope.state = 'login';
                        $scope.showSms = false;
                    } else if ($scope.hint == '新用户？注册') {
                        $scope.showSms = true;
                        $scope.hint = '老用户？';
                        $scope.operate = '注册';
                        $scope.telhint = '用来注册手机号';
                        $scope.pwdhint = '设置您的登录密码';
                        $scope.state = 'register';
                    }
                };
                $scope.findpwd = function () {
                    $scope.operate = '提交';
                    $scope.showSms = true;
                    $scope.state = 'findpwd';
                    $scope.telhint = '注册的手机号';
                    $scope.pwdhint = '新的登录密码';
                };
                $scope.close = function () {
                    $rootScope.showPanel = 'unvisiable';
                };
                $scope.getSMS = function () {
                    //数据校验
                    //noinspection JSUnresolvedVariable
                    if (!validate_mobile($scope.credential)) {
                        easy_dialog({
                            content: '请输入正确的手机号'
                        });
                        return false;
                    }
                    //noinspection JSUnresolvedVariable
                    $rjax.get({
                        url: '/Home/Util/ajaxSendCaptcha',
                        data: {
                            mobile: $scope.credential
                        },
                        callback: function (response) {
                            //noinspection JSUnresolvedVariable
                            if (response.rsc == '1001') {
                                var timedec = 120;
                                var timer = $interval(function () {
                                    if (timedec > 0) {
                                        $scope.IsDisabled = true;
                                        $scope.Hint = timedec + '秒';
                                    } else {
                                        $scope.IsDisabled = false;
                                        $scope.Hint = '获取验证码';
                                        $interval.cancel(timer);
                                    }
                                    timedec--;
                                }, 1000);
                            } else { //noinspection JSUnresolvedVariable
                                if (response.rsc == '1002') {
                                    easy_dialog({
                                        content: response.msg
                                    })
                                }
                            }
                        }
                    })
                };
                $scope.loginByPwd = function () {
                    //数据校验
                    //noinspection JSUnresolvedVariable
                    if (!validate_mobile($scope.credential)) {
                        easy_dialog({
                            content: '请输入正确手机号'
                        });
                        return false;
                    }
                    if ($scope.password == undefined) {
                        easy_dialog({
                            content: '密码不能为空'
                        });
                        return false;
                    }
                    if ($scope.sms_code == undefined && $scope.state == 'register') {
                        easy_dialog({
                            content: '验证码不能为空'
                        });
                        return false;
                    }
                    //noinspection JSUnresolvedVariable
                    var repwd = $scope.repassword;
                    if (!empty(repwd)) {
                        repwd = hex_md5(repwd);
                    }
                    //noinspection JSUnresolvedVariable
                    $rjax.post({
                        url: '/Home/Login/ajaxDoLogin',
                        data: {
                            user_tel: $scope.credential,
                            pwd: hex_md5($scope.password),
                            sms_code: $scope.sms_code,
                            repwd: repwd,
                            state: $scope.state
                        },
                        callback: function (response) {
                            //noinspection JSUnresolvedVariable
                            if (response.rsc == '1001') {
                                $rootScope.showPanel = 'unvisiable';
                                $timeout(function () {
                                    location.reload();
                                }, 500);
                                return true;
                            } else { //noinspection JSUnresolvedVariable
                                if (response.rsc == '1002') {
                                    if (response.state == 'findpwd') {
                                        $scope.hint = '新用户？注册';
                                        $scope.operate = '登录';
                                        $scope.showSms = false;
                                        $scope.state = 'login';
                                        $scope.telhint = '手机号';
                                        $scope.pwdhint = '登录密码';
                                    }
                                    easy_dialog({
                                        content: response.msg
                                    });
                                    return false;
                                }
                            }
                        }
                    });
                };
            }
        };
    }]);